package com.awtimage;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 在图片上画一个圆形
 */
public class ImageUtils {

    public static void main(String[] args) throws IOException {
        File srcImgFile = new File("d:/pic/test2.png");
        Image srcImg = ImageIO.read(srcImgFile);
        int srcImgWidth = srcImg.getWidth(null);
        int srcImgHeight = srcImg.getHeight(null);

        BufferedImage bufImg = new BufferedImage(srcImgWidth, srcImgHeight, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = bufImg.createGraphics();
        g.drawImage(srcImg, 0, 0, srcImgWidth, srcImgHeight, null);
        g.setColor(new Color(255,255,255,128));

        String waterMarkContent = "test";

        g.setPaint(new Color(224, 28, 28));
        BasicStroke stokeLine = new BasicStroke(15.0f);
        g.setStroke(stokeLine);
        int roundWidth = 200;
        g.drawRoundRect(0, 0, roundWidth,roundWidth,roundWidth,roundWidth);
        g.dispose();

        //待存储的地址
        String tarImgPath="d:/pic/b.png";
        // 输出图片
        FileOutputStream outImgStream = new FileOutputStream(tarImgPath);
        ImageIO.write(bufImg, "png", outImgStream);
        System.out.println("添加水印完成");
        outImgStream.flush();
        outImgStream.close();

    }

}
